# 捕获异常
try:
    open("D:\\ABCD.text", "r", encoding="utf-8")
except:
    print("异常,我将创建该文件")
    open("D:\\ABCD.text", "w", encoding="utf-8").close()
# 捕获指定异常
# 1/0
try:
    1 / 0
except  ZeroDivisionError as e:
    print("/0异常")
    print(e)
# print(name)

try:
    print(name)
except NameError as e :
    print("未命名异常")
    print(e)
#捕获多个异常
try:
    1/0
    print(name)
except (ZeroDivisionError,NameError) as e :
    print("未命名异常或/0异常")
    print(e)
#捕获全部 ，最基础的或顶级异常
try:
    1/0
except Exception as e:
    print("异常异常异常")
#异常else
try:
    0/1
    # 1/0
except Exception as e:
    print("异常异常异常")
else:
    print("代码正确")
#finally不管异常还是无异常，都要执行
try:
    0/1
    # 1/0
except Exception as e:
    print("异常异常异常")
else:
    print("代码正确")
finally:
    print("代码结束")
    # 列入f.close()